<?php
/**
 * Created by .
 * User: luogan
 * Date: 2022/1/17
 */

namespace app\admin\service;


use app\exception\ErrorException;
use app\model\AuthRoleModel;

class AuthRoleService extends BaseService
{
    public function getList($data)
    {
        $result = (new AuthRoleModel)
            ->withSearch($this->searchFields($data),$this->searchData($data))
            ->paginate($this->getLimit($data));
        if (!$result){
            throw new ErrorException();
        }
        return $result;
    }

    public function create($data)
    {

        $result = AuthRoleModel::create($data);
        if (!$result){
            throw new ErrorException();
        }
        admin_log('新增角色：'.$data['name'] .',角色id '.$result);
        return $result;
    }

    public function update($data)
    {

        $result = AuthRoleModel::where('id',$data['id'])->update($data);
        if (!$result){
            throw new ErrorException();
        }
        admin_log('编辑角色：角色id '.$data['id']);
        return $result;
    }

    public function getInfo($id)
    {
        $result = AuthRoleModel::find($id);
        if (!$result){
            throw new ErrorException();
        }
        return $result;
    }

    public function delete($id)
    {
        $result = AuthRoleModel::destroy($id);
        if (!$result){
            throw new ErrorException();
        }
        return $result;
        admin_log('删除角色：角色id' .$result);
    }


}
